package cn.itlaobing.service;

import cn.itlaobing.dao.VegetableDao;
import cn.itlaobing.entity.VegetablesDTO;
import cn.itlaobing.exception.BusinessException;

import java.sql.SQLException;
import java.util.List;

/**
 * @Description:
 * @Author: WangDong
 * @Date: 2017/11/10 16:52
 */
public class VegetableService {
    private VegetableDao vegetableDao=new VegetableDao();

    public List<VegetablesDTO> findAll(int pageIndex,int pageSize) throws BusinessException {
        List<VegetablesDTO>list=null;
        try {
            list=vegetableDao.findAll(pageIndex,pageSize);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new BusinessException(e.getMessage());
        }
        return list;
    }
    public List<VegetablesDTO> queryAll() throws BusinessException {

        List<VegetablesDTO> list=null;
        try {
             list=vegetableDao.queryAll();
        } catch (SQLException e) {
            e.printStackTrace();
            throw new BusinessException(e.getMessage());
        }
        return list;
    }
    public int update(VegetablesDTO vegetablesDTO) throws BusinessException {
        int r=0;
        try {
            r=vegetableDao.update(vegetablesDTO);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new BusinessException(e.getMessage());
        }
        return r;
    }

    public int delete(String id) throws BusinessException {
        int r=0;
        try {
            r=vegetableDao.deleteById(id);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new BusinessException(e.getMessage());
        }
        return r;
    }
}
